<template>
	<view>

		<uv-grid :col="2">
			<uv-grid-item v-for="item in list" :key="item.id">
				<view class="content">
					<view class="pkg-name">{{item.name}}</view>
					<view class="pkg-price"><text>￥{{item.money}}</text></view>
					<view class="pkg-desc"><text>{{item.cdesc}}</text></view>
					<view class="pkg-confirm">
						<uv-button :customStyle="customStyle" type="warning" shape='circle' size="small" @click="handelBuy(item)">立即开通</uv-button>
					</view>
				</view>

			</uv-grid-item>
		</uv-grid>



	</view>
</template>

<script>
	import { getSysGroupCountInfo, buyGroupCount } from '@/utils/http.js'
	export default {
		data() {
			return {
				list: [],
				customStyle: {
					// BorderRadius: '5px'
				},
				wxcode: ''
			}
		},
		onLoad() {
			this.fetchData()
			let that = this
			uni.login({
				success(res) {
					const { code } = res
					that.wxcode = code
				}
			})
		},
		methods: {
			async handelBuy(item) {
				var parm = { countid: item.id, code: this.wxcode }
				const { data, code } = await buyGroupCount(parm)
				const { appId, nonceStr, packageVal, paySign, signType, timestamp } = data
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: String(timestamp),
					nonceStr: nonceStr,
					package: packageVal,
					signType: signType,
					paySign: paySign,
					success: function(res) {
						uni.showToast({
							title: '支付成功',
						})
					},
					fail: function(err) {
						uni.showToast({
							title: '支付失败',
							icon: 'fail'
						})
					}
				})

			},
			fetchData() {
				getSysGroupCountInfo().then(res => {
					this.list = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #fff;
	}
	.content {
		width: 90%;
		margin: 20rpx auto;
		padding: 10rpx;
		background-color: #fff5ef;
		text-align: center;
		border-radius: 20upx;
		border:1px solid #ff5800;
		position: relative;

		.pkg-name {
			font-size: 28upx;
			position: absolute;
			left:-1px;
			top: -20upx;
			background: linear-gradient(to right, #ff3600, #ffa119);
			border-radius: 20upx 0 20upx 0;
			color:#fff;
			padding: 6upx 30upx;
			font-weight: bold;
		} 

		.pkg-price {
			color: #ff3600;
			font-size: 60upx;
			font-weight: bold;
			margin-top: 30upx;
		}

		.pkg-desc {
			color: #909399;
			font-size: 24upx;
			margin-top: 10upx;
		}

		.pkg-confirm {
			margin:20upx 60upx
		}
	}
</style>